package com.sunshine.wrongquestionset.room.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.sunshine.wrongquestionset.room.entity.QuestionTypeEntity


/**
 * @author sunshine
 * @date 2021/3/26
 * @see com.sunshine.wrongquestionset.room.entity.QuestionTypeEntity
 */
@Dao
interface QuestionTypeDao {
    //插入
    @Query("INSERT INTO question_type(name) VALUES(:name)")
    fun insert(name: String)

    @Insert(entity = QuestionTypeEntity::class, onConflict = OnConflictStrategy.IGNORE)
    fun insertByEntity(questionTypeEntity: QuestionTypeEntity)

    //通过实体删除
    @Delete(entity = QuestionTypeEntity::class)
    fun deleteByEntity(questionTypeEntity: QuestionTypeEntity)

    //通过名字删除
    @Query("DELETE FROM question_type WHERE name=:name")
    fun deleteByName(name: String)

    //查询所有
    @Query("SELECT * FROM question_type")
    fun selectAll(): LiveData<List<QuestionTypeEntity>?>

    @Query("SELECT name FROM question_type WHERE id=:id")
    fun selectTypeNameById(id: Int): LiveData<String?>

    //更新
    @Update(entity = QuestionTypeEntity::class, onConflict = OnConflictStrategy.IGNORE)
    fun update(questionTypeEntity: QuestionTypeEntity)
}